package com.totalinlink.dsl.poi.wrappers

import com.totalinlink.dsl.poi.WorkBookBuilder
import com.totalinlink.dsl.poi.constants.StyleWrapper

/**
 * Created by wangguangyu on 15/6/7.
 */
class FontWrapper extends NodeWrapper {

    def name
    def workbook

    def fontName
    def fontHeight
    def fontHeightInPoints
    def italic
    def strikeout
    def color
    def typeOffset
    def underline
    def charSet
    def boldweight
    def bold

    @Override
    void setNode(Object child) {

    }

    @Override
    void syncNode() {

        // create new font in workbook
        poiObject = workbook.poiObject.createFont()

        // set properties for font
        poiObject.fontName           = fontName
        // poiObject.fontHeight         = fontHeight
        poiObject.fontHeightInPoints = fontHeightInPoints
        poiObject.italic             = italic
        poiObject.strikeout          = strikeout
        poiObject.color              = color
        poiObject.typeOffset         = typeOffset
        poiObject.underline          = underline
        poiObject.charSet            = charSet
        poiObject.boldweight         = boldweight
        poiObject.bold               = bold

    }

    def FontWrapper(WorkBookBuilder workBookBuilder, Map attributes) {

        // call super for initialization
        super(workBookBuilder, attributes)
        workbook = workBookBuilder.workbook
        name = attributes.name

        // set properties for sync method
        fontName = attributes.fontName ?: "" // TODO: for default font name
        fontHeight = attributes.fontHeight ?: (short) 10
        fontHeightInPoints = attributes.fontHeightInPoints ?: (short) 0
        italic = attributes.italic ?: false
        strikeout = attributes.strikeout ?: false
        color = attributes.color ?: StyleWrapper.color_normal
        typeOffset = attributes.typeOffset ?: StyleWrapper.ss_none
        underline = attributes.underline ?: StyleWrapper.u_none
        charSet = attributes.charSet ?: StyleWrapper.default_charset
        boldweight = attributes.boldweight ?: (short) StyleWrapper.boldweight_normal
        bold = attributes.bold ?: false

    }
}
